#include <head.h>

int main(int argc, char const *argv[])
{
    int fd = open("hello.txt", O_CREAT | O_RDWR, 0666);
    // int fd_T = open("T.txt" , O_CREAT |O_RDWR , 0666);
    // 上锁
    flock(fd, LOCK_EX);
    int byte = 0;
    char buf[32] = "B";
    byte = read(fd, buf, sizeof(buf));
    printf("%s\n", buf);
    printf("%d\n", byte);
    int i = 10;
    int T_num = 0;
    
    lseek(fd, 0, SEEK_SET);
    flock(fd , LOCK_UN);
    close(fd);
    while (byte--)
    {
        int fd_1 = open("hello.txt", O_TRUNC | O_RDWR);

        // printf("%d\n",i);
        buf[byte] = '\0';
        write(fd, buf, strlen(buf));
        printf("%s\n", buf);
        lseek(fd, 0, SEEK_SET);
        sleep(1);
        close(fd_1);
    }

    // close(fd_T);
    return 0;
}
